package com.its.employee.controller;

import com.its.domain.BaseResult;
import com.its.employee.pojo.Employee;
import com.its.employee.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/employee")
public class EmployeeController {
    //依赖注入Service层属性
    @Autowired
    private EmployeeService employeeService;

    //声明单元方法：新增员工
    @PostMapping("/add")
    public BaseResult addEmployee(@RequestBody Employee employee){
        return BaseResult.ok(employeeService.addEmployeeService(employee));
    }

    //声明单元方法：删除员工
    @DeleteMapping("/delete")
    public BaseResult deleteEmployee(Integer employeeAccount){
        return BaseResult.ok(employeeService.deleteEmployeeService(employeeAccount));
    }


    //声明单元方法：修改员工信息
    @PutMapping("/update")
    public BaseResult updateEmployee(@RequestBody Employee employee){
        return BaseResult.ok(employeeService.updateEmployeeService(employee));
    }

    //声明单元方法：根据ID查询员工信息
    @GetMapping("/findById")
    public BaseResult selectEmployeeById(Integer employeeAccount){
        return BaseResult.ok(employeeService.selectEmployeeByEmployeeAccount(employeeAccount));
    }

    //声明单元方法：分页查询所有员工信息
    @GetMapping("/search")
    public BaseResult getAllEmployee(Integer page,Integer size){
        return BaseResult.ok(employeeService.getAllEmployee(page, size));
    }

}
